﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmChooseRubric : Page
    {
        protected GridView DataGridInfo;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        private int int_0 = 0;
        protected Label labChooseRubricInfo;
        protected Label labSumRubricInfo;
        protected LinkButton LBSelect;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "0";
        private string string_1 = "";
        protected HtmlInputHidden SumRecord;
        protected HtmlInputHidden txtSumCount;

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.DataItemIndex == -1)
            {
                this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
                this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            }
            else
            {
                e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
                if ((e.Row.DataItemIndex % 2) != 0)
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
                }
                else
                {
                    e.Row.Attributes.Add("bgcolor", "#FFFFFF");
                    e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
                }
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[1].Text = this.publicFun_0.RemoveHTML(e.Row.Cells[1].Text).Replace("&lt;BR&gt;", "").Replace("&lt;br&gt;", "").Replace("&nbsp;", "");
                string text = e.Row.Cells[0].Text;
                if (e.Row.Cells[1].Text.Length > 0x2d)
                {
                    e.Row.Cells[1].Text = "<a title=" + e.Row.Cells[1].Text + ">" + e.Row.Cells[1].Text.Substring(0, 0x2d) + "…</a>";
                }
                CheckBox box = (CheckBox) e.Row.Cells[0].FindControl("CheckBoxSelect");
                box.Attributes.Add("onclick", "AddNum('" + Convert.ToString(e.Row.RowIndex) + "')");
            }
        }

        protected void LBSelect_Click(object sender, EventArgs e)
        {
            int num;
            CheckBox box;
            if (this.LBSelect.Text == "选中所有")
            {
                int num2 = 0;
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    if (box.Enabled)
                    {
                        num2++;
                        this.labChooseRubricInfo.Text = num2.ToString();
                        box.Checked = true;
                    }
                }
                this.LBSelect.Text = "取消所选";
            }
            else
            {
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    box.Checked = false;
                }
                this.labChooseRubricInfo.Text = "0";
                this.LBSelect.Text = "选中所有";
            }
        }

        private void method_0()
        {
            string selectCommandText = "";
            string[] strArray = this.string_0.Split(new char[] { ',' });
            string str2 = "";
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].Trim() != "")
                {
                    if (str2.Trim().Length != 0)
                    {
                        str2 = str2 + " or SubjectID='" + strArray[i].Trim() + "' ";
                    }
                    else
                    {
                        str2 = " (SubjectID='" + strArray[i].Trim() + "' ";
                    }
                }
            }
            if (str2.Trim() != "")
            {
                str2 = str2 + ")";
            }
            else
            {
                str2 = " a.ID<>0 ";
            }
            selectCommandText = "select a.ID,a.RubricTitle,'中等' as Difficulty from  WorkRubric a,SubjectInfo b where a.SubjectID=b.ID and a.IsDel='N' and " + str2 + "  order by a.ID ";
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "RubricInfo");
            this.SumRecord.Value = dataSet.Tables["RubricInfo"].Rows.Count.ToString();
            this.DataGridInfo.DataSource = dataSet.Tables["RubricInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            adapter.Dispose();
            dataSet.Dispose();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_3 = new HttpCookie("ExamUserLevel");
            this.httpCookie_3 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_4 = new HttpCookie("ExamDeptID");
            this.httpCookie_4 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_2 = new HttpCookie("ExamDeptName");
            this.httpCookie_2 = base.Request.Cookies["ExamDeptName"];
            if ((this.httpCookie_0 == null) || (this.httpCookie_0.Value == ""))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.int_0 = Convert.ToInt32(base.Request["Num"].ToString());
                this.string_1 = base.Request["RubricID"].ToString();
                this.string_0 = base.Request["SubjectID"].ToString();
                if (!base.IsPostBack)
                {
                    this.labSumRubricInfo.Text = this.int_0.ToString();
                    this.method_0();
                    string[] strArray = this.string_1.Split(new char[] { '.' });
                    int num = 0;
                    for (int i = 0; i < strArray.Length; i++)
                    {
                        for (int j = 0; j < this.DataGridInfo.Rows.Count; j++)
                        {
                            Label label = (Label) this.DataGridInfo.Rows[j].Cells[3].FindControl("labID");
                            if (label.Text.Trim() == strArray[i].ToString().Trim())
                            {
                                CheckBox box = (CheckBox) this.DataGridInfo.Rows[j].FindControl("CheckBoxSelect");
                                box.Checked = true;
                                num++;
                            }
                        }
                    }
                    this.txtSumCount.Value = Convert.ToString((int) (this.DataGridInfo.Rows.Count + 1));
                    this.labChooseRubricInfo.Text = num.ToString();
                }
            }
        }
    }
}

